#include "common.hpp"
#include "fifo.hpp"
int main()
{
    // 检查获取key值是否出错
    int key = GetKey();
    cout << ToHex(key) << endl;

    // 创建shm,如果有报错的那种
    int shmid = CreatShm(defaultsize);
    cout << shmid << endl;

    // 挂接shm
    char *buffer = (char *)SetRelationship(shmid);

    // 进程间通信  这里借用管道的同步互斥机制，当写端终止写入或关闭，读端读到0，
    FIFO fifo(PAtH);
    Sync syn;
    syn.OpenRead();
    while (1)
    {
        if (!syn.wake()) // 读端读到0,退出循环
            break;
        cout << "from client message: " << buffer << endl;
        sleep(1);
    }

    // 解除挂接
    RemoveRelationship(buffer);
    // 销毁shm
    DelShm(shmid);
    return 0;
}